<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<%@include file="/common/common.jspf"%>
<style type="text/css">
.col-sm-3 {
	width: 15%;
	float: left;
}

.col-sm-9 {
	width: 85%;
	float: left;
}
</style>
</head>
<body>
	<div class="l_err" style="width: 100%; margin-top: 2px;"></div>
	<form id="form" name="form" class="form-horizontal" method="post"
		  enctype="multipart/form-data" action="${ctx}/commdoity/saveOrUpdate.shtml">
		<input type="hidden" class="form-control checkacc" value="${commodity.id}"
			name="id" id="id">
		<section class="panel panel-default">
			<div class="panel-body">
				<div class="form-group">
					<label class="col-sm-3 control-label">礼品名称</label>
					<div class="col-sm-9">
						<input type="text" class="form-control checkRole"
							placeholder="请输入礼品名称" name="name" id="name" value="${commodity.name}"/>
					</div>
				</div>
				<div class="line line-dashed line-lg pull-in"></div>
				<div class="form-group">
					<label class="col-sm-3 control-label">礼品属性</label>
					<div class="col-sm-9">
						<input type="text" class="form-control checkacc"
							placeholder="请输入礼品属性" name="property" id="property" value="${commodity.property}">
					</div>
				</div>
				<div class="line line-dashed line-lg pull-in"></div>
				<div class="form-group">
					<label class="col-sm-3 control-label">礼品描述</label>
					<div class="col-sm-9">
						<input type="text" class="form-control" placeholder="请输入礼品描述"
							name="description" id="description" value="${commodity.description }">
					</div>
				</div>
				<div class="line line-dashed line-lg pull-in"></div>
				<div class="form-group">
					<label class="col-sm-3 control-label">兑换积分</label>
					<div class="col-sm-9">
						<input type="text" class="form-control" placeholder="请输入兑换积分"
							name="integralPrice" id="integralPrice" value="${commodity.integralPrice }">
					</div>
				</div>
				<div class="line line-dashed line-lg pull-in"></div>
				<div class="form-group">
					<label class="col-sm-3 control-label">礼品价格</label>
					<div class="col-sm-9">
						<input type="text" class="form-control" placeholder="请输入礼品价格"
							name="money" id="money" value="${commodity.money }">
					</div>
				</div>
				
				<div class="line line-dashed line-lg pull-in"></div>
				<div class="form-group">
					<label class="col-sm-3 control-label">礼品图片</label>
					<div class="col-sm-9">
						<input type="file" class="form-control" placeholder="请输入礼品价格"
							name="urlName" id="urlName" accept="image/jpeg,image/bmp,image/gif,image/jpg,image/png">
					</div>
				</div>
				<div class="line line-dashed line-lg pull-in"></div>
			</div>
			<footer class="panel-footer text-right bg-light lter">
			<button type="submit" class="btn btn-success btn-s-xs">提交</button>
		</footer> 
	</section>
	</form>
	<script type='text/javascript'>
	 $(function() {
		 $("form").validate({
	 		submitHandler : function(form) {//必须写在验证前面，否则无法ajax提交
	 			var url=$("#urlName").val();
				url=url.toLowerCase();
				var cid=$("#id").val();
				if(cid==null||cid==""||url!=null&&url!=""){
					if(url.indexOf("bmp")>0||url.indexOf("jpg")>0||url.indexOf("jpeg")>0||url.indexOf("png")>0||url.indexOf("gif")>0){
						
					}else{
						layer.msg("请上传类型为bmp,jpg,jpeg,png,gif的图片文件");
						return false;
					}	
				}
	 			ly.ajaxSubmit(form,{//验证新增是否成功
	 				type : "post",
	 				dataType:"json",
	 				success : function(data) {
	 					if (data=="success") {
	 						layer.confirm('提交成功!是否关闭窗口?', function(index) {
	 							parent.grid.loadData();
					        	parent.layer.close(parent.pageii);
					        	return false;
	 						});
	 					} else {
	 						layer.alert('添加失败！', 3);
	 					}
	 				}
	 			});
	 		},
	 		rules : {
	 			"name" : {
					required : true
				},
				"integralPrice" : {
					required : true
				}
	 		},
			messages : {
				"name" : {
					required : "礼品名称不能为空",
				},
				"integralPrice" : {
					required : "礼品积分不能为空",
				}
			},
	 		errorPlacement : function(error, element) {//自定义提示错误位置
	 			$(".l_err").css('display','block');
	 			//element.css('border','3px solid #FFCCCC');
	 			$(".l_err").html(error.html());
	 		},
	 		success: function(label) {//验证通过后
	 			$(".l_err").css('display','none');
	 		}
	 	});
	 });
	</script>
</body>
</html>